home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- ** **
- ** Module: BoxPaint_document.c **
- ** **
- ** **
- ** Purpose: Code for a generic document **
- ** **
- ** **
- ** Authors: Michael Bishop **
- ** Nick Thompson **
- ** Robert Dierkes **
- ** **
- ** Copyright (C) 1996-1997 Apple Computer, Inc. All rights reserved. **
- ** **
- ** **
- *****************************************************************************/
-
-
-
- /******************************************************************************
- ** **
- ** INCLUDES **
- ** **
- *****************************************************************************/
-
- #include <Quickdraw.h> /* For Show/HideCursor routines */
- #include <assert.h>
-
- #include "BoxPaint_document.h"
- #include "BoxPaint_documentStructure.h"
-
- #include "BoxPaint_Support.h"
- #include "BoxPaint_window.h"
- #include "BoxPaint_texture.h"
- #include "BoxPaint_utility.h"
- #include "BoxPaint_cursor3D.h"
-
- #include "PictRead.h"
-
-
- /*
- ** QuickDraw 3D stuff
- */
- #include "QD3DMath.h"
- #include "QD3DCamera.h"
- #include "QD3DTransform.h"
- #include "QD3DGroup.h"
- #include "QD3DShader.h"
- #include "QD3DStorage.h"
- #include "QD3DIO.h"
- #include "QD3DPick.h"
- #include "QD3DRenderer.h"
- #include "QD3DAcceleration.h"
-
-
-
-
- /******************************************************************************
- ** **
- ** Local Functions **
- ** **
- *****************************************************************************/
-
- static void Document_Init(
- DocumentHdl theDocument);
-
- static unsigned long Document_DoPick(
- DocumentPtr theDocument,
- TQ3PickObject pickObject);
-
- static TQ3PickObject Document_NewPick(
- TQ3WindowPointPickData *pWPPData);
-
- static TQ3Status Document_GetPickingInfo(
- DocumentHdl theDocument,
- TQ3PickObject pickObject,
- TQ3Param2D *pTo,
- TQ3GeometryObject *pLastHitObject);
-
-
- /*===========================================================================*\
- *
- * Routine: Document_New()
- *
- * Comments: Loads a new Document with a blank (white) canvas for a texture
- *
- \*===========================================================================*/
-
- DocumentHdl Document_New(void)
- {
- DocumentHdl theDocument = (DocumentHdl)Utility_MemoryNew( sizeof(DocumentRec)) ;
-
- if( theDocument != NULL )
- {
- Document_Init(theDocument);
-
- /*
- ** Get a window for it
- */
- (**theDocument).fWindow = Window_New();
- if ((**theDocument).fWindow == NULL) goto bail;
-
- /*
- ** store a reference to the document record in the window's refcon
- */
- Window_SetDocument((**theDocument).fWindow, theDocument ) ;
-
- /*
- ** sets up the 3d data for the scene. Create view for QuickDraw 3D.
- */
- (**theDocument).fView = MyNewView( (**theDocument).fWindow ) ;
-
- if ((**theDocument).fView == NULL) {
- BP_DebugString("View could not be created!");
- goto bail; }
-
- /*
- ** the main display group:
- */
- (**theDocument).fModel = MyNewModel() ;
- if ((**theDocument).fModel == NULL) goto bail;
-
- /*
- ** the drawing styles:
- */
- (**theDocument).fInterpolation =
- Q3InterpolationStyle_New(kQ3InterpolationStyleNone) ;
- if ((**theDocument).fInterpolation == NULL) goto bail;
-
- (**theDocument).fBackFacing =
- Q3BackfacingStyle_New(kQ3BackfacingStyleRemove ) ;
- if ((**theDocument).fBackFacing == NULL) goto bail;
-
- (**theDocument).fFillStyle =
- Q3FillStyle_New(kQ3FillStyleFilled ) ;
- if ((**theDocument).fFillStyle == NULL) goto bail;
-
- (**theDocument).fCursor3D = Cursor3D_New(NULL);
- if ((**theDocument).fCursor3D == NULL) goto bail;
-
- Cursor3D_Hide((**theDocument).fCursor3D);
-
- /*
- ** By passing NULL as the first parameter, we tell the function to
- ** make a blank offscreen
- */
- (**theDocument).fTexture = Texture_New();
- if ((**theDocument).fTexture == NULL) goto bail;
-
- /*
- ** Add it to the model
- */
- Texture_SetToGroup((**theDocument).fTexture, (**theDocument).fModel) ;
-
- }
- return theDocument ;
- bail:
- Document_Dispose(theDocument);
- theDocument = NULL;
- return theDocument;
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Document_Dispose()
- *
- * Comments: Deallocates and deletes all the data in a document
- *
- \*===========================================================================*/
-
- void Document_Dispose( DocumentHdl theDocument)
- {
- assert(theDocument != NULL);
- assert(*theDocument != NULL);
-
- if ((**theDocument).fReferenceCount > 1) {
- (**theDocument).fReferenceCount--;
- }
-
- else {
-
- if ((**theDocument).fView != NULL)
- Q3Object_Dispose((**theDocument).fView) ;
-
- if ((**theDocument).fModel != NULL)
- Q3Object_Dispose((**theDocument).fModel) ;
-
- if ((**theDocument).fInterpolation != NULL)
- Q3Object_Dispose((**theDocument).fInterpolation) ;
-
- if ((**theDocument).fBackFacing != NULL)
- Q3Object_Dispose((**theDocument).fBackFacing) ;
-
- if ((**theDocument).fFillStyle != NULL)
- Q3Object_Dispose((**theDocument).fFillStyle) ;
-
- if ((**theDocument).fTexture != NULL)
- Texture_Dispose((**theDocument).fTexture);
-
- if ((**theDocument).fCursor3D != NULL)
- Cursor3D_Dispose((**theDocument).fCursor3D);
-
- if ((**theDocument).fWindow != NULL)
- Window_Dispose ( (**theDocument).fWindow ) ;
-
- /*
- ** Do this last
- */
- DisposeHandle( (Handle)theDocument ) ;
-
- }
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Document_GetReference()
- *
- * Comments: Returns a reference to a document object
- *
- \*===========================================================================*/
-
- DocumentHdl Document_GetReference(DocumentHdl theDocument)
- {
- assert(theDocument != NULL);
- assert(*theDocument != NULL);
-
- (**theDocument).fReferenceCount++;
-
- return theDocument;
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Document_GetTexture()
- *
- * Comments: Returns the Texture object associated with a document
- *
- \*===========================================================================*/
-
- TextureHdl Document_GetTexture(DocumentHdl theDocument)
- {
- assert(theDocument != NULL);
- assert(*theDocument != NULL);
-
- return (**theDocument).fTexture;
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Document_GetCamera()
- *
- * Comments: Returns the Camera associated with the document
- *
- \*===========================================================================*/
-
- TQ3CameraObject Document_GetCamera(DocumentHdl theDocument)
- {
- TQ3CameraObject theCamera;
-
- assert(theDocument != NULL);
- assert(*theDocument != NULL);
-
- Q3View_GetCamera((**theDocument).fView, &theCamera);
-
- return theCamera;
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Document_GetRendererPreferences()
- *
- * Comments: Returns the Renderer Preferences associated with the document
- *
- \*===========================================================================*/
-
- TQ3Status Document_GetRendererPreferences(DocumentHdl theDocument,
- long *theVendorID,
- long *theEngineID)
- {
- TQ3RendererObject theRenderer;
- TQ3Status theStatus = kQ3Success;
-
- assert(theDocument != NULL);
- assert(*theDocument != NULL);
-
- if (Q3View_GetRenderer((**theDocument).fView, &theRenderer) != kQ3Failure)
- {
- if (Q3Renderer_GetType(theRenderer) == kQ3RendererTypeInteractive)
- Q3InteractiveRenderer_GetPreferences(theRenderer, theVendorID, theEngineID);
- else theStatus = kQ3Failure;
-
- Q3Object_Dispose(theRenderer);
-
- } else theStatus = kQ3Failure;
-
- return theStatus;
- }
-
- /*===========================================================================*\
- *
- * Routine: Document_SetRendererPreferences()
- *
- * Comments: Sets the Renderer Preferences
- *
- \*===========================================================================*/
-
- TQ3Status Document_SetRendererPreferences(DocumentHdl theDocument,
- long theVendorID,
- long theEngineID)
- {
- TQ3RendererObject theRenderer;
- TQ3Status theStatus = kQ3Success;
-
- assert(theDocument != NULL);
- assert(*theDocument != NULL);
-
- if (Q3View_GetRenderer((**theDocument).fView, &theRenderer) != kQ3Failure)
- {
- if (Q3Renderer_GetType(theRenderer) == kQ3RendererTypeInteractive)
- {
- Q3InteractiveRenderer_SetPreferences(theRenderer, theVendorID, theEngineID);
- Q3View_SetRenderer((**theDocument).fView, theRenderer);
- }
- else theStatus = kQ3Failure;
-
- Q3Object_Dispose(theRenderer);
-
- } else theStatus = kQ3Failure;
-
-
- return theStatus;
- }
-
- /*===========================================================================*\
- *
- * Routine: Document_Open()
- *
- * Comments: Loads a new Document with a Pict for a texture
- *
- \*===========================================================================*/
-
- TQ3Status Document_Open(DocumentHdl theDocument)
- {
- PicHandle thePict = NULL;
-
- assert(theDocument != NULL);
- assert(*theDocument != NULL);
-
- thePict = GetPICTFile();
-
- if (thePict == NULL)
- return kQ3Failure;
-
- if ( theDocument != NULL )
- {
- /*
- ** Set the Picture in the Texture
- */
- if (Texture_SetPict((**theDocument).fTexture, thePict) == kQ3Failure)
- goto bail;
-
- /*
- ** Add that texture to the group
- */
- if (Texture_SetToGroup( (**theDocument).fTexture,
- (**theDocument).fModel ) == kQ3Failure)
- goto bail;
- }
-
- return kQ3Success;
-
- bail:
- KillPicture(thePict);
- return kQ3Failure;
-
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Document_Save()
- *
- * Comments: If you can figure out how to save the model,
- * This is a good place to put in that code :)
- *
- \*===========================================================================*/
-
- TQ3Status Document_Save(DocumentHdl theDocument)
- {
- assert(theDocument != NULL);
- assert(*theDocument != NULL);
-
- /*
- ** in the meantime, no op
- */
- theDocument;
- return kQ3Failure;
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Document_Draw()
- *
- * Comments: Draws the document in the current DrawContext
- *
- \*===========================================================================*/
-
- TQ3Status Document_Draw( DocumentPtr theDocument )
- {
- TQ3Status status = kQ3Failure;
-
- assert(theDocument != NULL);
-
- if ((status = Q3View_StartRendering(theDocument->fView)) != kQ3Failure)
- do {
- Document_SubmitScene( theDocument ) ;
- } while (Q3View_EndRendering(theDocument->fView) == kQ3ViewStatusRetraverse );
-
- bail:
-
- return status ;
-
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Document_Remap()
- *
- * Comments: Creates a higher resolution offscreen pixmap to texture our
- * box with. Uses the original picture and draws it into a new
- * buffer.
- *
- \*===========================================================================*/
-
- TQ3Status Document_Remap(DocumentHdl theDocument, long newResolution)
- {
- assert(theDocument != NULL);
- assert(*theDocument != NULL);
-
- if (Texture_GetResolution((**theDocument).fTexture) == newResolution)
- return kQ3Success;
-
- Texture_SetResolution((**theDocument).fTexture, newResolution);
-
- Texture_SetToGroup( (**theDocument).fTexture, (**theDocument).fModel );
-
- HLock((Handle)theDocument);
- Document_Draw(*theDocument);
- HUnlock((Handle)theDocument);
-
- return kQ3Success;
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Document_SubmitScene()
- *
- * Comments: If you make a function like this, you can easily use it
- * inside a Rendering or Picking or BoundingSphere/Box loop
- * (See Document_Draw)
- *
- \*===========================================================================*/
-
- TQ3Status Document_SubmitScene( DocumentPtr theDocument )
- {
- TQ3Status theStatus = kQ3Success;
-
- assert(theDocument != NULL);
-
- /*
- ** Interpolation
- */
- if (Q3Style_Submit( theDocument->fInterpolation,
- theDocument->fView) == kQ3Failure)
- theStatus = kQ3Failure;
-
- /*
- ** BackFacing
- */
- if (Q3Style_Submit( theDocument->fBackFacing ,
- theDocument->fView) == kQ3Failure)
- theStatus = kQ3Failure;
-
- /*
- ** FillStyle
- */
- if (Q3Style_Submit( theDocument->fFillStyle,
- theDocument->fView) == kQ3Failure)
- theStatus = kQ3Failure;
-
- /*
- ** Push
- */
- if (Q3Push_Submit(theDocument->fView) == kQ3Failure)
- theStatus = kQ3Failure;
-
- /*
- ** Rotation
- */
- if (Q3MatrixTransform_Submit( &theDocument->fRotation,
- theDocument->fView) == kQ3Failure)
- theStatus = kQ3Failure;
-
- /*
- ** Model
- */
- if (Q3DisplayGroup_Submit( theDocument->fModel,
- theDocument->fView) == kQ3Failure)
- theStatus = kQ3Failure;
-
- /*
- ** Pop
- */
- if (Q3Pop_Submit(theDocument->fView) == kQ3Failure)
- theStatus = kQ3Failure;
-
-
- HLock((Handle)theDocument->fCursor3D);
-
- /*
- ** Cursor
- */
- if (Cursor3D_Submit(*(theDocument->fCursor3D),
- theDocument->fView) == kQ3Failure)
- theStatus = kQ3Failure;
-
- HUnlock((Handle)theDocument->fCursor3D);
-
-
- return kQ3Success ;
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Document_Rotate()
- *
- * Comments: Rotates the model around while the mouse button is down.
- *
- \*===========================================================================*/
-
- void Document_Rotate(DocumentHdl theDocumentHdl)
- {
- TQ3Point2D newMouse;
- TQ3Point2D oldPoint;
- long mouseChanged = 0;
- float dx, dy;
- float width, height;
- float xRot, yRot;
- DocumentPtr theDocument;
-
- assert(theDocumentHdl != NULL);
-
- HideCursor();
-
- HLock((Handle)theDocumentHdl);
-
- theDocument = *theDocumentHdl;
-
- /*
- ** get the mouse in local co-ordinates,
- ** local to the current GrafPort
- */
- Utility_MyGetMouse(&oldPoint);
-
- width = theDocument->fWindow->portRect.left - theDocument->fWindow->portRect.right;
- height = theDocument->fWindow->portRect.bottom - theDocument->fWindow->portRect.top;
-
- while (Utility_MyStillDown()) {
-
- Utility_MyGetMouse(&newMouse);
-
- dx = oldPoint.y - newMouse.y;
- dy = newMouse.x - oldPoint.x;
-
- if ((dx != 0) || (dy != 0)) {
- TQ3Matrix4x4 tempMatrix;
-
- xRot = ((float) dx * kQ3Pi) / width;
- yRot = ((float) dy * kQ3Pi) / height;
-
- if ((xRot != 0.0) || (yRot != 0.0)) {
- Q3Matrix4x4_SetRotate_XYZ(&tempMatrix, xRot, yRot, 0.0);
- Q3Matrix4x4_Multiply(&theDocument->fRotation, &tempMatrix, &theDocument->fRotation);
-
- mouseChanged = 1;
- Document_Draw(theDocument);
- }
- }
- oldPoint.x = newMouse.x; oldPoint.y = newMouse.y;
- }
-
- ShowCursor();
-
- HUnlock((Handle)theDocumentHdl);
-
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Document_DrawOnTexture()
- *
- * Comments: As the cursor moves this paints on the texture with the
- * selected brush and color.
- *
- \*===========================================================================*/
-
- TQ3Status Document_DrawOnTexture( DocumentHdl pDocument)
- {
-
- TQ3Point2D newPoint,
- oldPoint;
- TQ3WindowPointPickData wppData;
- TQ3PickObject pickObject;
- TQ3Param2D from,
- to;
- TQ3Status mainStatus = kQ3Failure,
- status = kQ3Success;
- Boolean firstTime;
- TQ3GeometryObject theLastHitObject = NULL;
-
-
- assert(pDocument != NULL);
-
-
- from.u = -1.0;
- from.v = -1.0;
-
- HLock((Handle)pDocument);
- HLock((Handle)(**pDocument).fTexture);
-
- /*
- ** Swap the quickdraw Cursor for ours
- */
- HideCursor();
- Cursor3D_Show((**pDocument).fCursor3D);
-
- if (((**pDocument).fTexture == NULL) || (*(**pDocument).fTexture == NULL))
- {
- BP_DebugString("((**pDocument).fTexture == NULL) || (*(**pDocument).fTexture == NULL)");
- goto bail;
- }
-
- /*
- ** Create a pick
- */
- if((pickObject = Document_NewPick(&wppData)) == NULL) {
- BP_DebugString("Document_DrawOnTexture: pickObject == NULL.");
- goto bail;
- }
-
- /*
- ** Track the mouse and draw where it intersects the geometry
- */
- firstTime = true;
- oldPoint.x = oldPoint.y = 0;
- while (Utility_MyStillDown()) {
-
- Utility_MyGetMouse(&newPoint);
-
- /*
- ** Did mouse move?
- */
- if (oldPoint.x == newPoint.x &&
- oldPoint.y == newPoint.y) {
- continue;
- }
-
- /*
- ** Save new mouse position
- */
- oldPoint = newPoint;
-
- /*
- ** Adjust the pick point
- */
- wppData.point = newPoint;
-
- if (Q3WindowPointPick_SetPoint(pickObject, &wppData.point) == kQ3Failure) {
- goto bail;
- }
-
- if (Document_DoPick(*pDocument, pickObject) == 0) {
- /*
- ** No geometries hit
- */
- continue;
- }
-
- status = Document_GetPickingInfo(pDocument, pickObject, &to, &theLastHitObject);
-
- if ((status == kQ3Success) && ((from.u != to.u) || (from.v != to.v)))
- {
- TexturePtr theTexture = NULL;
-
- if (firstTime)
- {
- /*
- ** Texture_PaintLineRC needs valid row & column
- */
- from = to;
- firstTime = false;
- }
-
- /*
- ** Paint the line
- */
- theTexture = *((**pDocument).fTexture);
-
- Texture_PaintLineUV(theTexture, from, to);
-
- if ((Texture_Update(theTexture)) == kQ3Failure)
- {
- BP_DebugString("Document_DrawOnTexture: Q3MemoryStorage_SetBuffer failed.");
- goto bail;
- }
-
- if (Document_Draw(*pDocument) == kQ3Failure)
- {
- BP_DebugString("Document_DrawOnTexture: Document_Draw failed.");
- goto bail;
- }
-
- }
-
- /*
- ** Done process hits in the pick so now empty the list
- */
- Q3Pick_EmptyHitList(pickObject);
-
- from = to;
- }
- mainStatus = kQ3Success;
-
- bail:
-
- if (pickObject != NULL) {
- Q3Object_Dispose(pickObject);
- pickObject = NULL;
- }
-
- /*
- ** Hide the cursor
- */
- Cursor3D_Hide((**pDocument).fCursor3D);
-
- Document_Draw(*pDocument);
-
- HUnlock((Handle)(**pDocument).fTexture);
- HUnlock((Handle)pDocument);
-
- ShowCursor();
-
- return mainStatus;
-
-
- }
-
- /*===========================================================================*\
- *
- * Routine: Document_GetPickingInfo()
- *
- * Comments: Gets the picking information at point of intersection.
- * The line is drawn from "from" to "to".
- * (This could be improved to handle the cases when there
- * is a failure.)
- *
- \*===========================================================================*/
-
- TQ3Status Document_GetPickingInfo(
- DocumentHdl theDocument,
- TQ3PickObject pickObject,
- TQ3Param2D *pTo,
- TQ3GeometryObject *pLastHitObject)
- {
- TQ3Status status;
- Cursor3DPlacement theCursor3DPlacement; /* Where we want to put the cursor */
- TQ3Vector3D tempVector; /* used in calculation */
- TQ3GroupObject theHitObject; /* What we hit: it's the group
- holding the hit object */
- TQ3HitPath theHitPath; /* the group hierarchy */
- TQ3PickDetail testDetail; /* Used to check for the availability
- of certain types of pick info */
- const float cursorSize = 0.25; /* size in relation to the model being
- drawn on */
- status = kQ3Success;
- theHitObject = NULL;
-
- /*
- ** Params are as follows:
- **
- ** pickObject: the pick that we just picked (from a peck of
- ** pickled geometries)
- **
- ** 0: The mouse could be over more than one
- ** geometry (because there could be some hidden
- ** behind what we can see) SOOO, we have to specify
- ** that we only want to deal with the first object
- ** (the hit list starts at 0).
- **
- ** testDetail: Returned in this parameter are flags which indicate
- ** the availability of different types of pick
- ** information (for example, the xyz location or the UV
- ** corrdinates).
- **
- */
- if (Q3Pick_GetPickDetailValidMask(
- pickObject,
- 0,
- &testDetail) == kQ3Failure)
- return kQ3Failure;
-
- /*
- ** Get the hit object
- */
- if (testDetail & kQ3PickDetailMaskObject) {
-
- /*
- ** Using the ValidMask call allows us to check to see if it's worth looking
- ** at that field
- */
- if (Q3Pick_GetPickDetailData(
- pickObject,
- 0,
- kQ3PickDetailMaskObject,
- &theHitObject) == kQ3Failure)
-
- status = kQ3Failure;
- }
-
- /*
- ** Get the UV parameterization
- ** We need this so we know where to draw into our offscreen
- ** bitmap.
- */
- if (testDetail & kQ3PickDetailMaskUV) {
-
- if (Q3Pick_GetPickDetailData(
- pickObject,
- 0,
- kQ3PickDetailMaskUV,
- pTo) == kQ3Failure)
-
- status = kQ3Failure;
- }
-
- /*
- ** This is the place in xyz worldspace coordinates where we "hit"
- ** the model. We want to move our cursor there so we pass in a
- ** reference to the cursor location so it will be set.
- */
- if (testDetail & kQ3PickDetailMaskXYZ) {
-
- if (Q3Pick_GetPickDetailData(
- pickObject,
- 0,
- kQ3PickDetailMaskXYZ,
- &theCursor3DPlacement.cursorLocation) == kQ3Failure)
-
- status = kQ3Failure;
- }
-
- /*
- ** Get the surface normal
- ** We get this so we can orient the cursor.
- */
- if (testDetail & kQ3PickDetailMaskNormal) {
-
- if (Q3Pick_GetPickDetailData(
- pickObject,
- 0,
- kQ3PickDetailMaskNormal,
- &tempVector) == kQ3Failure)
-
- status = kQ3Failure;
- }
-
-
- /*
- ** We negate the normal so that it is pointing *into* the model
- ** because we want our cursor to point *into* the model.
- */
- Q3Vector3D_Negate(
- (const TQ3Vector3D *)&tempVector,
- &theCursor3DPlacement.toward);
-
- /*
- ** Since we don't have an up vector, we use a utility
- ** function to get one for us.
- */
- Utility_GetUpVector(
- &theCursor3DPlacement.toward,
- &theCursor3DPlacement.up);
-
- /*
- ** Pass in our placement (everything is already normalized).
- */
- Cursor3D_SetPlacement(
- (**theDocument).fCursor3D,
- &theCursor3DPlacement) ;
-
- /*
- ** We don't want to do this everytime
- */
- if (theHitObject != *pLastHitObject)
- {
- /*
- ** This code finds the group holding the object hit and
- ** scales the cursor according to it
- */
-
- /*
- ** Reset it for next time
- */
- *pLastHitObject = theHitObject;
-
- /*
- ** We don't need it anymore, just the object reference
- */
- Q3Object_Dispose(theHitObject);
-
- /*
- ** Get the path
- */
- if (testDetail & kQ3PickDetailMaskPath) {
-
- if (Q3Pick_GetPickDetailData(
- pickObject,
- 0,
- kQ3PickDetailMaskPath,
- &theHitPath) == kQ3Failure)
-
- status = kQ3Failure;
- }
-
- /*
- ** Get the group that holds the hit object
- */
- theHitObject = Utility_GetEnclosingGroup(
- &theHitPath);
-
- /*
- ** Change the cursor size against that group
- */
- Cursor3D_ChangeSizeAgainstGroup(
- (**theDocument).fCursor3D,
- theHitObject,
- (**theDocument).fView,
- cursorSize);
-
- /*
- ** Empty the pick path
- */
- Q3HitPath_EmptyData(&theHitPath);
-
- } else {
-
- Q3Object_Dispose(theHitObject);
- }
-
- return status;
- }
-
- /*===========================================================================*\
- *
- * Routine: Document_Idle()
- *
- * Comments: Does the Idle Action
- *
- \*===========================================================================*/
-
- void Document_Idle(DocumentHdl theDocument)
- {
- TQ3Matrix4x4 tmp;
-
- assert(theDocument != NULL);
- assert(*theDocument != NULL);
-
- /*
- ** For now, this just rotates the model
- */
-
- Q3Matrix4x4_SetRotate_XYZ(&tmp, 0.025, 0.03, 0.02);
- Q3Matrix4x4_Multiply(&(**theDocument).fRotation, &tmp, &(**theDocument).fRotation);
-
- HLock( (Handle)theDocument ) ;
-
- Document_Draw(*theDocument);
-
- HUnlock( (Handle)theDocument ) ;
- }
-
-
- /******************************************************************************
- ** **
- ** PRIVATE, LOCAL FUNCTIONS **
- ** **
- *****************************************************************************/
-
- /*===========================================================================*\
- *
- * Routine: Document_Init()
- *
- * Comments: Sets All Variables and objects common to all documents
- *
- \*===========================================================================*/
-
- void Document_Init( DocumentHdl theDocument)
- {
- assert(theDocument != NULL);
- assert(*theDocument != NULL);
-
- /*
- ** NULL out all of the parameters. Check out the header file for the
- ** parameter comments
- */
-
- (**theDocument).fReferenceCount = 0 ;
-
- (**theDocument).fWindow = NULL ;
-
- (**theDocument).fView = NULL;
- (**theDocument).fModel = NULL ;
- (**theDocument).fInterpolation = NULL ;
- (**theDocument).fBackFacing = NULL ;
- (**theDocument).fFillStyle = NULL ;
- Q3Matrix4x4_SetIdentity(&(**theDocument).fRotation);
-
- (**theDocument).fTexture = NULL;
-
- (**theDocument).fCursor3D = NULL;
-
- }
-
-
-
- /*===========================================================================*\
- *
- * Routine: Document_DoPick()
- *
- * Comments: Submits objects for picking and returns the number of
- * objects hit. This should be nearly identical to
- * Document_Draw.
- *
- \*===========================================================================*/
-
- static
- unsigned long Document_DoPick(
- DocumentPtr pDocument,
- TQ3PickObject pickObject)
- {
- TQ3ViewObject aView;
- TQ3ViewStatus viewStatus;
- unsigned long numHits;
-
- assert(pDocument != NULL);
-
- aView = pDocument->fView;
- numHits = 0;
-
- if (Q3View_StartPicking(aView, pickObject) == kQ3Success) {
- do {
- Document_SubmitScene( pDocument ) ;
-
- viewStatus = Q3View_EndPicking(aView);
-
- } while (viewStatus == kQ3ViewStatusRetraverse);
-
- if (viewStatus == kQ3ViewStatusDone) {
- Q3Pick_GetNumHits(pickObject, &numHits);
- }
- else {
- BP_DebugString("Document_DoPick: Q3View_EndPicking failed.");
- }
- }
- else {
- BP_DebugString("Document_DoPick: Q3View_StartPicking failed.");
- }
-
- return numHits;
- }
-
- /*===========================================================================*\
- *
- * Routine: Document_NewPick()
- *
- * Comments: Creates a new pick object.
- *
- \*===========================================================================*/
-
- static
- TQ3PickObject Document_NewPick(
- TQ3WindowPointPickData *pWPPData)
- {
- if (pWPPData == NULL) {
- return NULL;
- }
- pWPPData->point.x =
- pWPPData->point.y = 0.0;
-
- /*
- ** Create the window point pick
- */
- pWPPData->data.sort = kQ3PickSortNearToFar;
- pWPPData->data.numHitsToReturn = 1;
-
- /*
- ** We want all this info
- */
- pWPPData->data.mask = kQ3PickDetailMaskObject
- | kQ3PickDetailMaskPath
- | kQ3PickDetailMaskUV
- | kQ3PickDetailMaskXYZ
- | kQ3PickDetailMaskNormal
- ;
- pWPPData->vertexTolerance =
- pWPPData->edgeTolerance = 3.0;
-
- return (Q3WindowPointPick_New(pWPPData));
- }
-
-